package com.shaoshaohuo.app.view;

import android.content.Context;
import android.support.annotation.AttrRes;
import android.support.annotation.NonNull;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.shaoshaohuo.app.R;

/**
 * Created by Administrator on 2017/6/6.
 */

public class WhView extends FrameLayout implements View.OnClickListener {
    private int num = 0;
    private TextView tv_num;


    public WhView(@NonNull Context context) {
        this(context, null);
    }

    public WhView(@NonNull Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public WhView(@NonNull Context context, @Nullable AttributeSet attrs, @AttrRes int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        initview();
    }

    private void initview() {
        LayoutInflater.from(getContext()).inflate(R.layout.wz, this, true);
        Button iv_zeng = (Button) findViewById(R.id.iv_newzeng);
        iv_zeng.setOnClickListener(this);
        Button iv_jian = (Button) findViewById(R.id.iv_newjian);
        iv_jian.setOnClickListener(this);
        tv_num = (TextView) findViewById(R.id.tv_newnum);
        tv_num.setText(num + "");
    }

    public void setNum(int num) {
        this.num = num;
        tv_num.setText(num + "");
    }
private int wheathermax=1;
    public void setWheathermax(int a){
        this.wheathermax=a;
    }

    @Override
    public void onClick(View v) {

        int a = 0;
        switch (v.getId()) {
            case R.id.iv_newzeng:

                a = 0;
//                tv_num.setText(num + "");
                break;
            case R.id.iv_newjian:

                if (num > wheathermax) {

                } else {
                    return;
                }
                a = 1;

//                tv_num.setText(num + "");
                break;
        }
        if (whlistener != null) {
            whlistener.onwh(this, num, a);
        }

    }

    public int getnum() {
        return num;
    }

    private OnWhlistener whlistener;

    public void setWhlistener(OnWhlistener whlistener) {
        this.whlistener = whlistener;
    }

    public interface OnWhlistener {
        void onwh(View view, int num, int type);
    }
}
